package com.example.demo.controller;

import com.example.comon.domain.LoginUser;
import com.example.comon.domain.R;
import com.example.comon.utils.UserUtil;
import com.example.demo.domain.Bo.AddEvectionBo;
import com.example.demo.domain.Bo.EvectionListBo;
import com.example.demo.domain.Evection;
import com.example.demo.domain.Vo.EvectionVo;
import com.example.demo.service.IEvectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/evectionApplication")
@Api(value = "evectionApplication",tags = "出差申请控制器")
public class EvectionApplicationController {

    @Autowired
    private IEvectionService evectionService;


    @GetMapping("/getEvectionList")
    @ApiOperation("获取出差申请列表")
    public R<List<EvectionVo>> getLeaveList(EvectionListBo bo){
        Evection evection = new Evection();
        evection.setEvectionId(bo.getEmployeeId());
        List<EvectionVo>list = evectionService.selectEvection(evection);
        return R.success(list);
    }

    @PostMapping("/addEvection")
    @ApiOperation("增加出差申请")

    public R<Evection> addEvection(@RequestBody AddEvectionBo bo){
        Evection evection = new Evection();
        evection.setEmployeeId(bo.getEmployeeId());
        evection.setEvectionReason(bo.getEvectionReason());
        evection.setEvectionStartTime(bo.getEvectionStartTime());
        evection.setEvectionEndTime(bo.getEvectionEndTime());
        evection.setEvectionDays(bo.getEvectionDays());
        evectionService.insertEvection(evection);
        return R.success(evection);
    }

    @PostMapping("/updateEvectionById")
    @ApiOperation("修改出差申请")
    public R updateEvectionById(@RequestBody Evection evection) {
        evectionService.updateEvectionById(evection);
        return R.success();
    }

    @DeleteMapping("/delEvectionById")
    @ApiOperation("删除出差申请")
    public R delEvectionById(long evectionId){
        evectionService.delEvectionById(evectionId);
        return R.success();
    }

}

